package com.lalosoft.misgastos.view;


import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lalosoft.misgastos.R;
import com.lalosoft.misgastos.activities.MainActivity;
import com.lalosoft.misgastos.activities.SettingsActivity;

public class ActionBarView extends RelativeLayout {
	
	private TextView username;
	private RelativeLayout relativeSettings;

	public ActionBarView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}
	
	public ActionBarView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	
	public ActionBarView(Context context) {
		super(context);
		init(context);
	}
	
	private void init(final Context context){
		inflate(context, R.layout.action_bar, this);
		username = (TextView) findViewById(R.id.action_bar_username);
		relativeSettings = (RelativeLayout) findViewById(R.id.action_bar_relative);
		relativeSettings.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				MainActivity activity = (MainActivity) context;
				Intent i = new Intent(context, SettingsActivity.class);
				activity.startActivity(i);
				activity.finish();
			}
		});
	}
	
	public void setUserName(String name){
		this.username.setText(name);
	}

}
